/*    
    OpenMheg - A free MHEG-5 library
    Copyright (C) 2008 Dharmesh Malam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using Core.Model.Events;

namespace Core.Model.Data.Variables
{
    public class BooleanVariable : Variable
    {

        #region  Exchanged Attributes
        private bool originalValue;

        public bool OriginalValue
        {
            get { return originalValue; }
            set { originalValue = value; }
        }
        #endregion

        #region  Internal Attributes
        private bool value;

        public override void InittInternalAttributes ()
        {
            base.InittInternalAttributes();

            value = originalValue;
        }
        #endregion

        #region  Actions
        
        public void SetVariable (bool  value)
        {
            this.value = value;
        }

        public void TestVariable ( ComparasonTests op, bool comparisonValue )
        {
            switch ( op )
            {
                case ComparasonTests.Equal:
                    MHEGEngine.Instance.Handle( new TestEvent( this, value == comparisonValue ) );
                    break;

                case ComparasonTests.NotEqual:
                    MHEGEngine.Instance.Handle( new TestEvent( this, value != comparisonValue ) );
                    break;
                default:
                    base.TestVariable( op, comparisonValue );
                    break;
            }
        }

        public override bool Equals ( Object o )
        {
            if ( this == o ) return true;
            if ( !( o is BooleanVariable ) ) return false;

            return ( value == (( BooleanVariable ) o).Value );
            
        }

        public override int GetHashCode ()
        {
            return ( value ? 1 : 0 );
        }

        public bool Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        public override object Data 
        {
            get { return this.value; }
            set { this.value = (bool) value; }
        }

        public override string ToString ()
        {
            return base.ToString() +":"+Value.ToString();
        }
        #endregion


    }
}
